package org.mathcloud.math.core.generic.operator.algebra;

import org.mathcloud.math.core.common.operator.algebra.Abs;
import org.mathcloud.math.core.common.quantity.ComplexNumber;
import org.mathcloud.math.core.common.quantity.RealNumber;
import org.mathcloud.math.core.generic.operator.GenericUnaryOperator;
import org.mathcloud.math.core.generic.quantity.GenericRealNumber;

public class GenericAbs extends GenericUnaryOperator implements Abs
{
	public GenericAbs()
	{
		super();
		signature.setMMLContentTag("abs");
	}
	
	@Override
	public void calculate()
	{ 
		if ((getResultSignature()!=null)&&(operand!=null))
		{
			if (operand.getSignature().isRealNumberSignature())
				res = new GenericRealNumber(Math.abs(((RealNumber)operand).getValue()));
			else if (operand.getSignature().isComplexNumberSignature())
				res = new GenericRealNumber(((ComplexNumber)operand).getValue());			
		}
	}			
}
